When an Android system loads an image, a large portion of a Java heap memory is occupied to decode the image. However, the size of the Java heap memory for an application process in the Android system is limited. When the usage of the Java heap memory by the application process is relatively high, the Java heap memory easily becomes insufficient, thereby triggering out of memory (“OOM”).
To reduce the usage of the Java heap memory, decoded image data can be cached for reuse, thus reducing the needs for decoding images. For example, after a bitmap object is decoded from a network or a local resource, an Least Recently Used (LRU) cache management can be implemented by using LinkedHashMap (i.e., a Map data structure implemented based on link and hash). That is, recently used bitmap objects are saved for reuse by using strong reference (e.g., saved to the LinkedHashMap), thereby achieving reuse of the bitmap objects and improving user application experience. When the quantity of cached data reaches a predetermined value, the cached bitmap objects not frequently used are deleted to release memory for new bitmap objects.
However, when the existing image cache manner is used to achieve the reuse of decoded image data, a bitmap object is still decoded at the layer of a Java framework, and the decoded bitmap object is still cached in the Java heap memory, causing the Java heap memory to easily become insufficient and triggering OOM.